package service.impl;

import dao.SupplierMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pojo.Supplier;
import service.SupplierService;

import java.util.List;

@Transactional
@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Override
    public List<Supplier> selectAllSuppliersByName(String supplierName) {
        return supplierMapper.selectAllSuppliersByName(supplierName);
    }

    @Override
    public boolean add(Supplier supplier) {
        boolean result=false;
        try {
            if(supplierMapper.add(supplier)>0){
                result=true;
                // 测试事物回滚时，打开注释
//                throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public boolean delete(int id) {
        boolean result=false;
        try {
            if(supplierMapper.delete(id)>0){
                result=true;
                // 测试事物回滚时，打开注释
//                throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public boolean update(Supplier supplier) {
        boolean result=false;
        try {
            if(supplierMapper.update(supplier)>0){
                result=true;
                // 测试事物回滚时，打开注释
//                throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<Supplier> selectPages(String code, String name, int pageIndex, int pageSize) {
        return supplierMapper.selectPages(code,name,pageIndex,pageSize);
    }

    @Override
    public int selectCount(String code, String name) {
        return supplierMapper.selectCount(code,name);
    }

    @Override
    public Supplier selectById(Integer id) {
        return supplierMapper.selectById(id);
    }

    @Override
    public List<Supplier> selectAllSuppliers() {
        return supplierMapper.selectAllSuppliers();
    }
}
